//
//  HJWelcomViewController.m
//  12期传智微博HJ
//
//  Created by mac on 15-2-3.
//  Copyright (c) 2015年 jun. All rights reserved.
//

#import "HJWelcomViewController.h"
#import "HJUITabBarController.h"

@interface HJWelcomViewController ()
/**
 *  头像
 */
@property (weak, nonatomic) IBOutlet UIImageView *iconImage;
/**
 *  欢迎
 */
@property (weak, nonatomic) IBOutlet UILabel *welcomeLabel;
/**
 *  头像Y约束
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconconsY;

@end

@implementation HJWelcomViewController

- (void)viewDidLoad {
    //设置圆角
    self.iconImage.layer.cornerRadius = 50;
    self.iconImage.layer.masksToBounds = YES;
    //加载头像
    HJAccount *account = [HJAccount accountFromSandbox];
    NSURL *iconURL = [NSURL URLWithString:account.profile_image_url];
    //获取SDWebImage管理对象
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    //利用管理对象下载图片
    [manager downloadImageWithURL:iconURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (finished) {
            self.iconImage.image = image;
        }
    }];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //让头像做动画
    [UIView animateWithDuration:1.5 animations:^{
        self.iconconsY.constant += 150;
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1.5 animations:^{
            //让文字淡出
            self.welcomeLabel.alpha = 1.0;
        } completion:^(BOOL finished) {
            //切换控制器
            HJUITabBarController *tabBarVc = [[HJUITabBarController alloc]init];
            UIWindow *window = [UIApplication sharedApplication].keyWindow;
            window.rootViewController = tabBarVc;
        }];
    }];
}

@end
